setArguments( array( 'description' => __( 'Displays Amazon product links contextually related to the current page contents.', 'amazon-auto-links' ), ) ); new AmazonAutoLinks_RevealerCustomFieldType( $this->oProp->sClassName ); add_filter( 'style_' . $this->oProp->sClassName, array( $this, 'replyToModifyCSSRules' ) ); add_filter( 'options_' . $this->oProp->sClassName, array( $this, 'replyToSetDefaultOptions' ) ); } /** * @return string */ public function replyToModifyCSSRules( $sCSSRules ) { return $sCSSRules . ' .links-style-label code, .links-style-label > div { font-size: 0.8em; } .widget .amazon-auto-links-input-label-container { width: auto; } .widget form-table .amazon-auto-links-section-table, .widget .amazon-auto-links-sectionset, .widget .amazon-auto-links-section { margin-bottom: 0; } .widget .amazon-auto-links-section-title > h3 { margin: 0.2em 0; } '; } /** * Sets the default options. * @return array * @since 3.3.0 */ public function replyToSetDefaultOptions( $aOptions ) { $_aDefaults = apply_filters( 'aal_filter_default_unit_options_search', array() ); return $aOptions + $_aDefaults; } /** * Sets up the form. * * Alternatively you may use load_{instantiated class name} method. */ public function load() { $_oOption = AmazonAutoLinks_Option::getInstance(); $_bAPIConnected = $_oOption->isAPIConnected(); if ( ! $_bAPIConnected ) { $this->addSettingField( array( 'field_id' => '_message_dummy_id', 'type' => '_message', 'description' => array( sprintf( __( 'Please set up API keys first from this page.', 'amazon-auto-links' ), AmazonAutoLinks_PluginUtility::getAPIAuthenticationPageURL() ), ), 'save' => false, 'attributes' => array( 'name' => '', ), ) ); return; } $_aClasses = array( 'AmazonAutoLinks_FormFields_Widget_ContextualProduct', 'AmazonAutoLinks_FormFields_Unit_Common', 'AmazonAutoLinks_FormFields_Unit_CommonAdvanced', 'AmazonAutoLinks_FormFields_Button_Selector', 'AmazonAutoLinks_FormFields_Unit_Cache', 'AmazonAutoLinks_FormFields_Unit_Template', 'AmazonAutoLinks_FormFields_Widget_Visibility', ); $this->_addFieldsByFieldClass( $_aClasses ); // Product filters $this->addSettingSections( array( 'title' => __( 'Product Filters', 'amazon-auto-links' ), 'section_id' => 'product_filters', 'collapsible' => array( 'collapsed' => true, 'type' => 'button', 'container' => 'section', ), ) ); // Add fields $this->addSettingFields( 'product_filters' ); // Set the target section. $this->_addFieldsByFieldClass( array( 'AmazonAutoLinks_FormFields_ProductFilter', 'AmazonAutoLinks_FormFields_ProductFilter_Image', ) ); // Add fields $this->addSettingFields( '_default' ); // Set the target section. $this->_addFieldsByFieldClass( array( 'AmazonAutoLinks_FormFields_ProductFilterAdvanced', ) ); add_filter( 'field_definition_' . $this->oProp->sClassName . '_button_id', array( $this, 'replyToSetActiveButtonLabels' ) ); } /** * Modifies the 'button_id' field to add lables for selection. * @return array * @since 3.3.0 */ public function replyToSetActiveButtonLabels( $aFieldset ) { $aFieldset[ 'label' ] = $this->_getActiveButtonLabelsForFields(); return $aFieldset; } /** * @return array * @since 3.3.0 */ private function _getActiveButtonLabelsForFields() { static $_aCache; if ( isset( $_aCache ) ) { return $_aCache; } $_aButtonIDs = AmazonAutoLinks_PluginUtility::getActiveButtonIDs(); $_aLabels = array(); foreach( $_aButtonIDs as $_iButtonID ) { $_aLabels[ $_iButtonID ] = get_the_title( $_iButtonID ) . ' - ' . get_post_meta( $_iButtonID, 'button_label', true ); } $_aCache = $_aLabels; return $_aCache; } /** * Adds form fields by the given class names. * @since 3.0.3 * @return void */ private function _addFieldsByFieldClass( $aClassNames ) { foreach( $aClassNames as $_sClsssName ) { $_oFields = new $_sClsssName; $_aFields = 'AmazonAutoLinks_FormFields_Unit_Template' === $_sClsssName ? $_oFields->get( '', 'contextual_widget' ) : $_oFields->get(); foreach( $_aFields as $_aField ) { $this->_addField( $_aField ); } } } /** * @since 3.1.2 */ private function _addField( $aField ) { $_sFieldID = $this->oUtil->getElement( $aField, 'field_id' ); if ( $this->oUtil->hasSuffix( 'available_page_types', $_sFieldID ) ) { $this->oUtil->setMultiDimensionalArray( $aField, array( 'default', 'search' ) , true ); } $this->addSettingFields( $aField ); } /** * Validates the submitted form data. * * @callback filter validation_{instantiated class name} */ public function validate( $aSubmit, $aStored, $oAdminWidget ) { // When the user does not set the API keys, an empty widget form will be rendered and thus inputs will be empty. if ( empty( $aSubmit ) ) { return $aSubmit; } // @fixed 3.6.0 Not sure why {...}_search was used here. It should be {...}_contextual // $_aDefaults = apply_filters( 'aal_filter_default_unit_options_search', array() ); $_aDefaults = apply_filters( 'aal_filter_default_unit_options_contextual', array() ); $aSubmit = array( 'unit_type' => 'contextual' ) // 3.6.0+ for Ajax unit loading + $aSubmit + $_aDefaults; // Sanitize the form inputs. $_oItemFormatValidator = new AmazonAutoLinks_FormValidator_ItemFormat( $aSubmit, $aStored ); $aSubmit = $_oItemFormatValidator->get(); return $aSubmit; } /** * Print out the contents in the front-end. * * @callback filter content_{instantiated class name} */ public function content( $sContent, $aArguments, $aFormData ) { //$sContent = $sContent // . '